package com.jia.controller;


import com.jia.common.lang.R;
import com.jia.entity.SysRolePermission;
import com.jia.service.SysRolePermissionService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杜佳佳
 * @since 2021-05-23
 */
@RestController
@RequestMapping("/admin/sys/rolePermission")
@Api(tags = "系统角色权限管理")
public class SysRolePermissionController {

    @Autowired
    private SysRolePermissionService sysRolePermissionService;

    @GetMapping("/list")
    public R list() {
        List<SysRolePermission> list = sysRolePermissionService.list();
        return R.ok().data("list",list);
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
        SysRolePermission byId = sysRolePermissionService.getById(id);
        return R.ok().data("data",byId);
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") String id){
        sysRolePermissionService.removeById(id);
        return R.ok().message("删除成功");
    }

    @PostMapping("/save")
    public R save(@RequestBody SysRolePermission sysRolePermission) {
        sysRolePermissionService.save(sysRolePermission);
        return R.ok().message("新增成功");
    }

    @PutMapping("/update")
    public R update(@RequestBody SysRolePermission sysRolePermission){
        sysRolePermissionService.updateById(sysRolePermission);
        return R.ok().message("修改成功");
    }

}

